package com.zzx.boot.message;

import com.zzx.boot.emus.ChatTypes;
import com.zzx.boot.websocket.session.WebSocketSession;
import io.netty.channel.ChannelHandlerContext;
import lombok.AllArgsConstructor;
import lombok.Data;

import java.io.Serializable;

@Data
public class ConnectMessage extends Message {
    private String userId;
    public ConnectMessage() {
        this.type = ChatTypes.CONNECT.getType();
    }

    public ConnectMessage(String userId,String type) {
        this.type = type;
        this.userId = userId;
    }

    @Override
    public ChatTypes getType() {
        return ChatTypes.CONNECT;
    }

    @Override
    public void send(ChannelHandlerContext ctx) {
        WebSocketSession.addSession(this.getUserId(),ctx.channel());
        ConnectMessage connectMessage = new ConnectMessage(this.getUserId(), "SUCCESS");
        connectMessage.setMessage("连接websocket成功");
        ctx.channel().writeAndFlush(this.toText(connectMessage));
    }
}
